package com.yanqu.road.server.cmd.banquet.crossBanquet.auto;

import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.entity.task.args.ConsumeItemArgs;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.banquet.CrossBanquetProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.banquet.BanquetModule;
import com.yanqu.road.server.manger.banquet.BanquetMgr;
import com.yanqu.road.server.manger.banquet.CrossBanquetMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.Protocol;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

@Cmd(code = Protocol.S_BANQUET_CROSS_ACTIVITY_REWARD_ADD, desc = "定时来加人气道具")
public class BanquetAutoAddPopCmd extends AbstractCommand {

	private CrossBanquetProto.CrossAddAutoBanquetPopRewardResp reqMsg;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		reqMsg = CrossBanquetProto.CrossAddAutoBanquetPopRewardResp.parseFrom(packet.getBytes());
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		if(player != null){
			if(reqMsg.getPopValue() > 0){
				CrossBanquetMgr.addBanquetPopularityAndIntegral(player,reqMsg.getPopValue(),0, eLogMoneyType.BanquetAutoJoinReward.getValue());
			}
			if(reqMsg.getJoinTimes() > 0){
				BanquetMgr.addBanquetJoinTimes(player,reqMsg.getJoinTimes());
			}
			if(reqMsg.getIngots() > 0){
				int goodsId = GameConfig.GAME_MONEY_INGOTS;
				player.notifyListener(eGamePlayerEventType.ConsumeItemRank.getValue(), new ConsumeItemArgs(goodsId, BigInteger.valueOf(reqMsg.getIngots())));
			}
		}
	}

	@Override
	public void sendData(GamePlayer player) {

	}
}
